<template>
	<view class="navBox" :style="'height:calc(94rpx + ' + statusBarHeight + 'px)'">
		<view class="navTop" :class="needBorder ? 'isBorder' : ''" :style="'background-color:' + backgroundColor">
			<view :style="'height:' + statusBarHeight + 'px'"></view>
			<view class="navTitle">
				<view v-if="showBack" class="backBox" @click="isBack">
					<image src="../static/back_black.png" class="icon-back"></image>
					<text style="margin-left: 10rpx;" v-if="backTitle">{{backTitle}}</text>
				</view>
				<slot></slot>
				<text style="font-size: 30rpx;font-weight: bold;" v-if="title">{{ title }}</text>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	name: 'navTop',
	props: {
		backTitle:{
			type:String,
			default:''
		},
		showBack: {
			type: Boolean,
			default: false
		},
		backColor: {
			type: String,
			default: 'black'
		},
		needBorder: {
			type: Boolean,
			default: false
		},
		backgroundColor: {
			type: String,
			default: 'white'
		},
		title: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			statusBarHeight: uni.getSystemInfoSync()['statusBarHeight']
		};
	},
	methods: {
		isBack() {
			let pages = getCurrentPages(); //获取加载的页面
			console.log('isBack', pages);
			if (pages.length <= 1) {
				uni.reLaunch({
					url: '/pages/index/index'
				});
				return;
			}
			uni.navigateBack({
				delta: 1
			});
		}
	},
	created() {}
};
</script>

<style lang="scss" scoped>
.isBorder {
	border-bottom: 1rpx solid #f2f2f2;
}
.navBox {
	font-size: 32rpx;
	position: relative;
}
.icon-back {
	width: 18rpx;
	height: 32rpx;
	margin-top: -5rpx;
	display: inline-block;
	vertical-align: middle;
}
.backBox {
	position: absolute;
	left: 0;
	top: 0;
	min-width: 100rpx;
	height: 94rpx;
	line-height: 94rpx;
	padding-left: 30rpx;
	text-align: left;
}
.navTitle {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #000;
	font-size: 26rpx;
	font-weight: bold;
	width: 100vw;
	height: 94rpx;
}
.navTop {
	top: 0;
	left: 0;
	z-index: 996;
	width: 100vw;
}
</style>
